package com.great.codewars;

import static org.junit.Assert.assertEquals;

import java.lang.StringBuilder;

/**
 * 以空格来切割，字母倒序
 * 
 * @author chenchengxiang
 *
 */
public class ReverseWords {
	public static String reverseWords(final String original) {
		String[] array = original.split(" ");
		if (array.length == 0)
			return original;
		int i = 0;
		for (String string : array) {
			//String 反转
			array[i] = new StringBuilder(string).reverse().toString();
			i++;
		}
		for (String string : array) {
			System.out.println(string+":"+string.length());
		}
		//中间用空格切割
		return String.join(" ", array);
	}

	public static void main(String[] args) {
		System.out.println(ReverseWords.reverseWords("The quick brown fox jumps over the lazy dog."));
		assertEquals("ehT kciuq nworb xof spmuj revo eht yzal .god",
				ReverseWords.reverseWords("The quick brown fox jumps over the lazy dog."));
		System.out.println(ReverseWords.reverseWords("a b c d"));
		assertEquals("elppa", ReverseWords.reverseWords("apple"));
		assertEquals("a b c d", ReverseWords.reverseWords("a b c d"));
		System.out.println("double  spaced  words");
		assertEquals("elbuod  decaps  sdrow", ReverseWords.reverseWords("double  spaced  words"));

	}
}